package com.huike.clues.service.impl;


import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.mapper.TbClueMapper;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.utils.DateUtils;
import com.huike.common.utils.SecurityUtils;
import org.apache.poi.ss.formula.functions.Now;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.DateFormat;
import java.util.Date;
import java.util.List;

/**
 * 线索跟进记录Service业务层处理
 * @date 2022-04-22
 */
@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {

    @Autowired
    private TbClueTrackRecordMapper tbClueTrackRecordMapper;

    @Autowired
    private TbClueMapper tbClueMapper;
    /**
     * 新增线索跟进记录
     * 从controller层接收ClueTrackRecordVo对象
     * 分别对tb_clue表和tb_clue_track_record表操作
     * @param clueTrackRecordVo
     * @return
     */
    @Override
    public Integer addClueTrackRecord(ClueTrackRecordVo clueTrackRecordVo) {
        TbClue tbClue =new TbClue();
        TbClueTrackRecord tbClueTrackRecord = new TbClueTrackRecord();
        BeanUtils.copyProperties(clueTrackRecordVo,tbClue);
        //更改状态
        tbClue.setStatus(TbClue.StatusType.FOLLOWING.getValue());
        //要操作哪个线索,传入线索id
        tbClue.setId(clueTrackRecordVo.getClueId());
        BeanUtils.copyProperties(clueTrackRecordVo,tbClueTrackRecord);
        //当前创建记录的人
        tbClueTrackRecord.setCreateBy(SecurityUtils.getUsername());
        //当前时间
        tbClueTrackRecord.setCreateTime(DateUtils.getNowDate());
        //更改clue表数据
        tbClueMapper.updateTbClue(tbClue);

        return tbClueTrackRecordMapper.addClueTrackRecord(tbClueTrackRecord);
    }

    @Override
    public List<TbClueTrackRecord> list(Long clueId) {
        List<TbClueTrackRecord> list = tbClueTrackRecordMapper.list(clueId);
        return list;
    }
}
